package o;

import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import o.aih.c;

public final class aiv implements aih, c {
    private aiw ʼ;
    private TrackGroupArray ʽ;
    public final aih[] ˊ;
    private final aia ˋ;
    private c ˎ;
    private final IdentityHashMap<aiu, Integer> ˏ;
    private final ArrayList<aih> ॱ = new ArrayList();
    private aih[] ᐝ;

    public /* synthetic */ void ˏ(aiw o_aiw) {
        ˎ((aih) o_aiw);
    }

    public aiv(aia o_aia, aih... o_aihArr) {
        this.ˋ = o_aia;
        this.ˊ = o_aihArr;
        this.ʼ = o_aia.ˏ(new aiw[0]);
        this.ˏ = new IdentityHashMap();
    }

    public void ˏ(c cVar, long j) {
        this.ˎ = cVar;
        Collections.addAll(this.ॱ, this.ˊ);
        for (aih ˏ : this.ˊ) {
            ˏ.ˏ(this, j);
        }
    }

    public void h_() throws IOException {
        for (aih h_ : this.ˊ) {
            h_.h_();
        }
    }

    public TrackGroupArray ˋ() {
        return this.ʽ;
    }

    public long ॱ(akz[] o_akzArr, boolean[] zArr, aiu[] o_aiuArr, boolean[] zArr2, long j) {
        int i;
        int i2;
        int[] iArr = new int[o_akzArr.length];
        int[] iArr2 = new int[o_akzArr.length];
        for (i = 0; i < o_akzArr.length; i++) {
            if (o_aiuArr[i] == null) {
                i2 = -1;
            } else {
                i2 = ((Integer) this.ˏ.get(o_aiuArr[i])).intValue();
            }
            iArr[i] = i2;
            iArr2[i] = -1;
            if (o_akzArr[i] != null) {
                TrackGroup ˊ = o_akzArr[i].ˊ();
                for (i2 = 0; i2 < this.ˊ.length; i2++) {
                    if (this.ˊ[i2].ˋ().ˋ(ˊ) != -1) {
                        iArr2[i] = i2;
                        break;
                    }
                }
            }
        }
        this.ˏ.clear();
        Object obj = new aiu[o_akzArr.length];
        aiu[] o_aiuArr2 = new aiu[o_akzArr.length];
        akz[] o_akzArr2 = new akz[o_akzArr.length];
        ArrayList arrayList = new ArrayList(this.ˊ.length);
        i2 = 0;
        long j2 = j;
        while (i2 < this.ˊ.length) {
            i = 0;
            while (i < o_akzArr.length) {
                o_aiuArr2[i] = iArr[i] == i2 ? o_aiuArr[i] : null;
                o_akzArr2[i] = iArr2[i] == i2 ? o_akzArr[i] : null;
                i++;
            }
            long ॱ = this.ˊ[i2].ॱ(o_akzArr2, zArr, o_aiuArr2, zArr2, j2);
            if (i2 == 0) {
                j2 = ॱ;
            } else if (ॱ != j2) {
                throw new IllegalStateException("Children enabled at different positions.");
            }
            Object obj2 = null;
            for (i = 0; i < o_akzArr.length; i++) {
                if (iArr2[i] == i2) {
                    amm.ˏ(o_aiuArr2[i] != null);
                    obj[i] = o_aiuArr2[i];
                    obj2 = 1;
                    this.ˏ.put(o_aiuArr2[i], Integer.valueOf(i2));
                } else if (iArr[i] == i2) {
                    amm.ˏ(o_aiuArr2[i] == null);
                }
            }
            if (obj2 != null) {
                arrayList.add(this.ˊ[i2]);
            }
            i2++;
        }
        System.arraycopy(obj, 0, o_aiuArr, 0, obj.length);
        this.ᐝ = new aih[arrayList.size()];
        arrayList.toArray(this.ᐝ);
        this.ʼ = this.ˋ.ˏ(this.ᐝ);
        return j2;
    }

    public void ˎ(long j, boolean z) {
        for (aih ˎ : this.ᐝ) {
            ˎ.ˎ(j, z);
        }
    }

    public void ॱ(long j) {
        this.ʼ.ॱ(j);
    }

    public boolean ˋ(long j) {
        if (this.ॱ.isEmpty()) {
            return this.ʼ.ˋ(j);
        }
        int size = this.ॱ.size();
        for (int i = 0; i < size; i++) {
            ((aih) this.ॱ.get(i)).ˋ(j);
        }
        return false;
    }

    public long ˏ() {
        return this.ʼ.ˏ();
    }

    public long ˎ() {
        int i;
        long ˎ = this.ˊ[0].ˎ();
        for (i = 1; i < this.ˊ.length; i++) {
            if (this.ˊ[i].ˎ() != -9223372036854775807L) {
                throw new IllegalStateException("Child reported discontinuity.");
            }
        }
        if (ˎ != -9223372036854775807L) {
            aih[] o_aihArr = this.ᐝ;
            int length = o_aihArr.length;
            i = 0;
            while (i < length) {
                aih o_aih = o_aihArr[i];
                if (o_aih == this.ˊ[0] || o_aih.ˎ(ˎ) == ˎ) {
                    i++;
                } else {
                    throw new IllegalStateException("Unexpected child seekToUs result.");
                }
            }
        }
        return ˎ;
    }

    public long ॱ() {
        return this.ʼ.ॱ();
    }

    public long ˎ(long j) {
        long ˎ = this.ᐝ[0].ˎ(j);
        for (int i = 1; i < this.ᐝ.length; i++) {
            if (this.ᐝ[i].ˎ(ˎ) != ˎ) {
                throw new IllegalStateException("Unexpected child seekToUs result.");
            }
        }
        return ˎ;
    }

    public long ॱ(long j, abv o_abv) {
        return this.ᐝ[0].ॱ(j, o_abv);
    }

    public void ˊ(aih o_aih) {
        this.ॱ.remove(o_aih);
        if (this.ॱ.isEmpty()) {
            int i = 0;
            for (aih ˋ : this.ˊ) {
                i += ˋ.ˋ().ॱ;
            }
            TrackGroup[] trackGroupArr = new TrackGroup[i];
            aih[] o_aihArr = this.ˊ;
            int length = o_aihArr.length;
            int i2 = 0;
            int i3 = 0;
            while (i2 < length) {
                TrackGroupArray ˋ2 = o_aihArr[i2].ˋ();
                int i4 = ˋ2.ॱ;
                i = i3;
                i3 = 0;
                while (i3 < i4) {
                    int i5 = i + 1;
                    trackGroupArr[i] = ˋ2.ˋ(i3);
                    i3++;
                    i = i5;
                }
                i2++;
                i3 = i;
            }
            this.ʽ = new TrackGroupArray(trackGroupArr);
            this.ˎ.ˊ(this);
        }
    }

    public void ˎ(aih o_aih) {
        this.ˎ.ˏ(this);
    }
}
